package com.google.code.basic.oop;

import java.util.List;

public class Reports {

	public static void displayNetworkElementData(List<NetworkElementConnector> connectors) {

		for (NetworkElementConnector connector : connectors) {
			System.out.printf("Connection Name: %s, Network Element Name: %s, Network Element IP: %s, " +
							"User name: %s, User password: %s\n",
					connector.getConnectionName(),
					connector.getNetworkElement().getNetworkElementName(),
					connector.getNetworkElement().getIp(),
					connector.getAccount().getUserName(),
					connector.getAccount().getPassword());
		}
	}
	
	public static void displayGeneralAlarmInfo(List<Alarm> alarms) {
		System.out.printf("Total: %d alarms\n", alarms.size());
		System.out.printf("Minor(1): %d alarms\n", getNumberOfAlarmsBySeverity(1,alarms));
		System.out.printf("Major(2): %d alarms\n", getNumberOfAlarmsBySeverity(2,alarms));
		System.out.printf("Critical(3): %d alarms\n", getNumberOfAlarmsBySeverity(3,alarms));
	}
	
	public static void displayAlarms(List<Alarm> alarms, int numberOfAlarms) {
		int numberOfAlarmsToDisplay = 0;
		int counter = 0;
		if (numberOfAlarms > alarms.size()) { 
			throw new AlarmRangeException("Number of Alarms should be > Number of Alarms to Display");
		}
		if (numberOfAlarms == 0) {
			numberOfAlarmsToDisplay = alarms.size(); 
		}
		else {
			numberOfAlarmsToDisplay = numberOfAlarms; 
		}
		for (Alarm alarm: alarms) {
			if(counter >= numberOfAlarmsToDisplay){
    			break; 
    		}
       		System.out.printf("Alarm Id: %d; Alarm number: %d; Alarm severity: %d; Alarm text: %s; Alarm time: %tc; Ceased time %tc \n",
							alarm.getAlarmId(),
							alarm.getAlarmNumber(),
							alarm.getSeverity(),
							alarm.getAlarmText(),
							alarm.getAlarmTime(),
							alarm.getClearTime());
    			counter++;
    	}
	}
	
	public static int getNumberOfAlarmsBySeverity(int severity, List<Alarm> alarms) {
		int result = 0;
		for (Alarm alarm: alarms) {
			if (alarm.getSeverity() == severity) {
				result++;
			}
		}
		return result;
	}
}
